package project.Dao;/*
 *  @Author Mr.long
 *  @QQ 1507468405
 *  @Creat 2021/11/24 - 23:13
 */

import Utils.JDBCTemp;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import project.Domain.Notice;

import java.util.List;

public class NoticeDao {
    //    创建JdbcTemplate对象用于执行sql语句
    private JdbcTemplate template = new JdbcTemplate(JDBCTemp.getDataSource());


    public List<Notice> queryAll(int id) {
        //根据id查询该用户的上级编号，来查询其可见的通知列表
        String sql = "select * from xm05_notice_info where publisherID = ?";
        List<Notice> noticeList = template.query(sql, new BeanPropertyRowMapper<Notice>(Notice.class), id);
        return noticeList;
    }

    public boolean insert(Notice notice) {
        String sql = "insert into xm05_notice_info(publisherID,publisherName,title,content,deliverTime) values(" +
                "?,?,?,?,?)";
        int update = template.update(sql, notice.getPublisherID(),notice.getPublisherName(), notice.getTitle(),
                notice.getContent(),
                notice.getDeliverTime());
        return update > 0;
    }

    public boolean delete(int id) {
        String sql = "delete from xm05_notice_info where id = ?";
        int update = template.update(sql, id);
        return update > 0;
    }

    public boolean update(Notice update) {
        String sql = "update xm05_notice_info set publisherID=?,title=?,content=?,deliverTime=? where id = ?";
        int update1 = template.update(sql, update.getPublisherID(), update.getTitle(), update.getContent(), update.getDeliverTime(),
                update.getId());
        return update1>0;
    }
}
